describe("App.AccountTransaction",function(){
    var accountTransaction;
    beforeEach(function(){
        accountTransaction = App.AccountTransaction.create();
    });

    it("isCredit--false",function(){
        accountTransaction.set('depositAmount',23.02);
        accountTransaction.set('withdrawalAmount',123.02);
        expect(accountTransaction.get('isCredit')).toBe(false);
    });

    it("isCredit--true",function(){
        accountTransaction.set('depositAmount',22);
        accountTransaction.set('withdrawalAmount',0);
        expect(accountTransaction.get('isCredit')).toBe(true);
    });

    it("transferAmount--return super",function(){
        accountTransaction.set('depositAmount',22);
        accountTransaction.set('withdrawalAmount',0);
        expect(accountTransaction.get('transferAmount')).toBe(22);
    });

    it("transferAmount--return Abs value",function(){
        accountTransaction.set('depositAmount',22);
        accountTransaction.set('withdrawalAmount',221);
        expect(accountTransaction.get('transferAmount')).toBe(Math.abs(221));
    });
});

describe("App.PaymentTransaction",function(){
    var paymentTransactionObject;
    beforeEach(function(){
      paymentTransactionObject = App.PaymentTransaction.create();
    });

    it("type to be not empty",function(){
       paymentTransactionObject.set('transactionTypeCode','15');
       var t_transactionTypeCode = paymentTransactionObject.get('transactionTypeCode');
       expect(Ember.isEmpty(t_transactionTypeCode)).toBe(false);
       expect(paymentTransactionObject.get('type')).toBe('15');
    });

    it("type is empty",function(){
        paymentTransactionObject.set('transactionTypeCode','');
        var t_transactionTypeCode = paymentTransactionObject.get('transactionTypeCode');
        expect(Ember.isEmpty(t_transactionTypeCode)).toBe(true);
        expect(paymentTransactionObject.get('type')).toBe('');
    });

    it('typeDesc', function() {
        var t_transaction = {
            key : "2011-10-12",
            transferDate: "2011-10-12T05:30:00.000+0530",
            fromAccountNumber: "22539552026",
            currencyCode: "INR",
            amount: 2000,
            transactionType : "15`Transfer Between Own Accounts"
        };

        var transaction =  App.PaymentTransaction.create(t_transaction, {_account:App.HaveAccount.create()});

        expect(transaction.get('typeDesc')).toEqual("Transfer Between Own Accounts");

    });

    it('typeDesc with empty', function() {
        var t_transaction = {
            key : "2011-10-12",
            transferDate: "2011-10-12T05:30:00.000+0530",
            fromAccountNumber: "22539552026",
            currencyCode: "INR",
            amount: 2000
        };

        var transaction =  App.PaymentTransaction.create(t_transaction, {_account:App.HaveAccount.create()});

        spyOn(BreezeUtils, 'getPaymentTypeDescription').andReturn("");
        expect(transaction.get('typeDesc')).toEqual("");

    });

    it('displayableObjectInList', function() {

        var t_transaction = {   "id":"2011-10-12",
                                "title":"Unknown",
                                "amount":2000,
                                "currencyCode":"IDR",
                                "isNegative":false,
                                "fromAccountNumber": "02110029565",
                                "fromAccountCurrencyCode": "USD"
                            };

        var transaction =  App.PaymentTransaction.create(t_transaction);

        var expectedOutput = {  "title":"Unknown",
                                "secondLabel":"02110029565, USD",
                                "amount":2000,
                                "currencyCode":"IDR",
                                "isNegative":true
                            };
        expect(JSON.stringify(transaction.get('displayableObjectInList'))).toEqual(JSON.stringify(expectedOutput));
    });

    it('displayableObject', function() {

        var t_transaction = {
            "toAccountVO":{"accountDescription":"IBFT_Khan_ACC","accountNumber":"18521000507822","currencyCode":"IDR"},
            "merchantVO":{},
            "transactionMode":"I",
            "channel":"IBKBMW",
            "currencyCode":"IDR",
            "transactionTypeCode":"18`InterBank Fund Transfer",
            "remark":"Transferring funds to a third party account in another bank",
            "amount":203,
            "transferDate":"2012-06-11T21:06:03.000+0530",
            "transactionStatus":{"transactionId":"00000000-0000-0000-1206-112002022200","transactionStatus":"2"},
            "fromAccount":{"accountDescription":"aXcess Plus","accountNumber":"22510132401","currencyCode":"IDR"},
            "toAccount":{"accountDescription":"premium Plus","accountNumber":"45610132401","currencyCode":"IDR"},
            "recurring":{"isRecurring":false},
            "merchantId":"",
            "merchant":{},
            "destinationAccountName":"IBFT_Khan_ACC",
            "createdDate":"2012-06-11T20:02:35.784+0530",
            "updatedBy":"9171981351",
            "updatedDate":"2012-06-11T20:02:35.784+0530"
        }

        var transaction =  App.PaymentTransaction.create(t_transaction, {_account:App.HaveAccount.create()});

        var expectedOutput = [
            {
                "key": "Type",
                "value": "Unknown"
            },
            {
                "key": "Status",
                "value": "SUBMITTED"
            },
            {
                "key": "From",
                "value": "22510132401, IDR"
            },
            {
                "key":"To",
                "value":"45610132401, IDR"
            },
            {
                "key": "Amount",
                "value": {
                    "currencyCode": "IDR",
                    "amount": 203
                },
                "isAmount": true
            },
            {
                "key": "Date",
                "value": "Monday, 11 June 2012"
            },
            {
                "value": "Transferring funds to a third party account in another bank"
            }
        ];
        expect(JSON.stringify(transaction.get('displayableObject'))).toEqual(JSON.stringify(expectedOutput));
    });

});